package com.zzy.mccjt.mybatis;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;

import java.time.Instant;

/**
 * @program: mccjt-cloud
 * @description: 自动设置值
 * @author: zhouyang.zheng
 * @create: 2022-08-10 17:31
 **/
public class MetaObjectHandlerConfig implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        //默认未删除
        setFieldValByName("deleted", false, metaObject);
        //创建时间默认当前时间
        setFieldValByName("createAt", Instant.now(), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        //修改时间
        setFieldValByName("updateAt", Instant.now(), metaObject);
    }
}

